import 'package:dajia/src/component/mine.dart';
import 'package:dajia/src/util/IconUtil.dart';
import 'package:flutter/material.dart';
import 'package:dajia/src/component/home.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/scheduler.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();

  // @override
  // void initState() {
  //   print("initState1111");
  // }

  // @override
  // void didChangeDependencies() {
  //   print("didChangeDependencies1111");
  // }

  // @override
  // void deactivate() {
  //   // TODO: implement deactivate
  //   print("deactivate1111");
  // }

  // @override
  // void dispose() {
  //   // TODO: implement dispose
  //   print("dispose1111");
  // }


}

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  int _counter = 0;
  String _text = "";

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  getData(){

  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    // TODO: implement didChangeAppLifecycleState
    super.didChangeAppLifecycleState(state);
    print("didChangeAppLifecycleState=$state");
    if (state == AppLifecycleState.resumed){
      // went to Background
    }
    if (state == AppLifecycleState.inactive) {
      // came back to Foreground
    }
    if (state == AppLifecycleState.paused) {
      // 暂停
    }
    if (state == AppLifecycleState.detached) {
      // 小
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    print("initState");
    getData();
    SchedulerBinding.instance.addPostFrameCallback((timeStamp) { 
      print("addPostFrameCallback=$timeStamp");
    });
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    print("didChangeDependencies");
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    print("deactivate");
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print("dispose");
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FadeAnimatedTextKit(
              duration: Duration(milliseconds: 5000), //动画持续时间
              isRepeatingAnimation: true,
              text: ["文字", "动起来", "common!!!"],
              textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
            ),
            RotateAnimatedTextKit(
              onTap: () {
                print("Tap Event"); //组件点击事件
              },
              text: ["小包子", "切图仔", "最后的倔强"],
              textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
              alignment: AlignmentDirectional.topStart,
            ),
            // TyperAnimatedTextKit(
            //     text: [
            //       "学习使我快乐",
            //       "切图仔最后的倔强",
            //     ],
            //     textStyle: TextStyle(fontSize: 30.0, fontFamily: "Bobbers"),
            //     textAlign: TextAlign.start,
            //     alignment: AlignmentDirectional.topStart // or Alignment.topLeft
            //     ),
            // TypewriterAnimatedTextKit(
            //     text: [
            //       "切图仔最后的倔强",
            //     ],
            //     textStyle: TextStyle(fontSize: 30.0, fontFamily: "Agne"),
            //     textAlign: TextAlign.start,
            //     alignment: AlignmentDirectional.topStart // or Alignment.topLeft
            //     ),
            // ScaleAnimatedTextKit(
            //     text: ["Flutter", "轮子", "推荐"],
            //     textStyle: TextStyle(fontSize: 70.0, fontFamily: "Canterbury"),
            //     textAlign: TextAlign.start,
            //     alignment: AlignmentDirectional.topStart // or Alignment.topLeft
            //     ),
            // ColorizeAnimatedTextKit(
            //     text: [
            //       "小包子",
            //       "flutter",
            //     ],
            //     textStyle: TextStyle(fontSize: 32.0, fontFamily: "Horizon"),
            //     colors: [
            //       Colors.purple,
            //       Colors.blue,
            //       Colors.yellow,
            //       Colors.red,
            //     ],
            //     textAlign: TextAlign.start,
            //     alignment: AlignmentDirectional.topStart // or Alignment.topLeft
            //   ),
            Icon(IconUtil.home,size: 30),
            Icon(IconUtil.mine,size: 30),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            Text(
              '$_text',
              style: Theme.of(context).textTheme.headline6,
            ),
            FlatButton(
              child: Text("Open New Route"),
              textColor: Colors.red,
              onPressed: () {
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return new home();
                }));
              },
            ),
            FlatButton(
              child: Text("Open New Route"),
              textColor: Colors.red,
              onPressed: () async {
                var result = await Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  var mine2 = new mine(text: "我是首页过来的");
                  return mine2;
                }));
                print("路由值返回:$result");
                setState(() {
                  _text = result;
                });
              },
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }


}
